﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Frm_Recherche_fourniss

    Private Sub Frm_Recherche_fourniss_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Gestion_Fourn.Enabled = True
    End Sub

    Private Sub Frm_Recherche_fourniss_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Frm_Gestion_Fourn.Enabled = False
        comb_selectionnez.SelectedIndex = 0
    End Sub

    Private Sub txt_mot_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_mot.TextChanged
        Dim mot As String = ""
        If comb_selectionnez.SelectedItem = "Nom" Then
            mot = "Nom"
        ElseIf comb_selectionnez.SelectedItem = "Prenom" Then
            mot = "Prenom"
        ElseIf comb_selectionnez.SelectedItem = "Categorie" Then
            mot = "Categorie"
        ElseIf comb_selectionnez.SelectedItem = "Nom de L'entreprise" Then
            mot = "Nom_entreprise"

        ElseIf comb_selectionnez.SelectedItem = "Nom de L'interlocuteur" Then
            mot = "Nom_interlocuteur"
        End If
        Try
            List_tous.Items.Clear()
            Cmd = New SqlCommand("Select * From Fournisseus where " & mot & " like '%" & txt_mot.Text & "%'", Con)
            open()
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Categorie"), Dr("Nom"), Dr("Prenom"), Dr("Nom_entreprise"), Dr("Id_Fournisseur")})
                List_tous.Items.Add(Line)
            Loop
            Dr.Close()
            cnClose()
            If txt_mot.Text = "" Then
                List_tous.Items.Clear()
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    Private Sub btn_selectionnez_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_selectionnez.Click
        Try
        Dim n As Integer
        With List_tous
            If .SelectedIndices.Count > 0 Then

                For i As Integer = 0 To .SelectedIndices.Count - 1
                        n = CInt(.Items(.SelectedIndices(i)).SubItems(4).Text)
                    Next

                For i As Integer = 0 To Frm_Gestion_Fourn.List_tous.Items.Count - 1
                        If Frm_Gestion_Fourn.List_tous.Items(i).SubItems(7).Text = n Then
                            Frm_Gestion_Fourn.List_tous.Items(i).Focused = True
                            Frm_Gestion_Fourn.List_tous.Items(i).Selected = True
                        End If
                Next
                Me.Close()

            Else
                MsgBox("Vous n'avez selectionner aucun Fournisseur !", MsgBoxStyle.Critical, "Réssayer !")
            End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class